﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using PR.BusinessEntity.RamanSyrtsou;
using System.Collections.Generic;
using System.Collections.Specialized;

namespace PR.UI.Web.RamanSyrtsou
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ExecutePreActions();

            results.DataSource = new WebServiceClientRamanSyrtsou().GetAllPRObjects();
            results.DataBind();
        }

        private void ExecutePreActions()
        {
            NameValueCollection queryString = HttpContext.Current.Request.QueryString;

            if(ContainsKey(queryString, "action"))
            {
                string actionName = queryString["action"];

                if (actionName == "delete" && ContainsKey(queryString, "id"))
                {
                    string id = queryString["id"];
                    int prObjectId = int.Parse(id);

                    new WebServiceClientRamanSyrtsou().DeletePRObject(prObjectId);
                }
            }
        }

        internal static bool ContainsKey(NameValueCollection queryString, string key)
        {
            foreach (var element in queryString.AllKeys)
            {
                if (element == key)
                {
                    return true;
                }
            }

            return false;
        }
    }
}
